package org.example.petadoption.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.example.petadoption.entity.Orders;
import org.example.petadoption.entity.OrdersUserProductDTO;

import java.util.List;

/**
 * <p>
 * 订单表 Mapper 接口
 * </p>
 *
 * @author PetAdoption
 * @since 2025-10-20
 */
public interface OrdersMapper extends BaseMapper<Orders> {

    @Select("""
        SELECT 
            o.id,
            o.order_no,
            o.user_id,
            o.merchant_id,
            o.product_id,
            o.product_name,
            o.product_price,
            o.quantity,
            o.total_amount,
            o.status,
            o.payment_time,
            u.username AS username,
            u.phone AS user_phone,
            p.cover_image AS cover_image,
            m.name AS merchant_name,
            m.contact_person AS merchant_contact,
            m.contact_phone AS merchant_phone,
            m.address AS merchant_address
        FROM orders o
        LEFT JOIN user u ON o.user_id = u.id
        LEFT JOIN product p ON o.product_id = p.id
        LEFT JOIN merchant m ON o.merchant_id = m.id
        WHERE o.user_id = #{merchantId}
    """)
    List<OrdersUserProductDTO> selectOrdersByMerchant(@Param("merchantId") int merchantId);

}
